import request from '@/utils/request';

/**
 * 发送消息
 * @param {Object} data - 消息数据对象，包含receiverId, content, type
 * @returns {Promise} - 请求响应
 */
export function sendMessage(data) {
  return request({
    url: '/api/chat/message',
    method: 'post',
    data
  });
}

/**
 * 获取聊天历史
 * @param {Number} senderId - 发送者ID
 * @param {Number} receiverId - 接收者ID
 * @param {Number} page - 页码
 * @param {Number} size - 每页数量
 * @returns {Promise} - 请求响应
 */
export function getChatHistory(senderId, receiverId, page = 1, size = 20) {
  return request({
    url: '/api/chat/history',
    method: 'get',
    params: {
      senderId,
      receiverId,
      page,
      size
    }
  });
}

/**
 * 标记消息为已读
 * @param {Number} messageId - 消息ID
 * @returns {Promise} - 请求响应
 */
export function markAsRead(messageId) {
  return request({
    url: `/api/chat/read/${messageId}`,
    method: 'put'
  });
}

/**
 * 标记所有消息为已读
 * @param {Number} receiverId - 接收者ID
 * @returns {Promise} - 请求响应
 */
export function markAllAsRead(receiverId) {
  return request({
    url: `/api/chat/read/all/${receiverId}`,
    method: 'put'
  });
}

/**
 * 获取未读消息数量
 * @param {Number} receiverId - 接收者ID
 * @returns {Promise} - 请求响应
 */
export function getUnreadCount(receiverId) {
  return request({
    url: `/api/chat/unread/count/${receiverId}`,
    method: 'get'
  });
}

/**
 * 获取未读消息列表
 * @param {Number} receiverId - 接收者ID
 * @returns {Promise} - 请求响应
 */
export function getUnreadMessages(receiverId) {
  return request({
    url: `/api/chat/unread/${receiverId}`,
    method: 'get'
  });
}

/**
 * 获取联系人列表
 * @param {Number} userId - 用户ID
 * @returns {Promise} - 请求响应
 */
export function getContacts(userId) {
  return request({
    url: '/api/user/contacts',
    method: 'get',
    params: { userId }
  });
} 